define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'proxlog/index',
                    add_url: 'proxlog/add',
                    // edit_url: 'proxlog/edit',
                    del_url: 'proxlog/del',
                    multi_url: 'proxlog/multi',
                    table: 'proxylog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showExport:false,
                searchFormVisible: true,
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'user.username', title: __('User.username')},
                        {field: 'regione', title: __('Regione'),operate:false},
                        {field: 'province', title: __('Province'),operate:false},
                        {field: 'city', title: __('City') ,operate:false},
                        {field: 'area', title: __('Area'),operate:false},

                        {field: 'server_type', title: __('Server_type'), searchList: {"0":__('Server_type 0'),"1":__('Server_type 1'),"2":__('Server_type 2'),"3":__('Server_type 3'),"5":__('Server_type 5')}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'is_agent', title: __('Is_agent'), searchList: {"1":__('Is_agent 1'),"0":__('Is_agent 0')}, formatter: Table.api.formatter.normal},
                        {field: 'price', title: __('价格'),operate:false},
                        {field: 'fullname', title: __('姓名'),operate:false},
                        {field: 'phone', title: __('手机号'),operate:false},
                        {field: 'account', title: __('银行卡号'),operate:false},
                        {field: 'branch', title: __('银行姓名'),operate:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [


                                {
                                    name: 'detail',
                                    width: "80px",
                                    height:'50px',
                                    title: __('审核'),
                                    text: __('审核'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'proxlog/detail',
                                    callback: function (data) {

                                        Fast.api.ajax({
                                            url:'proxlog/up',
                                            data:{
                                                id:data.id,
                                                status:data.status
                                            },

                                        }, function(datat, ret){
                                            //成功的回调
                                            Layer.alert( ret.msg, {title: "审核"});
                                            $('.btn-refresh').trigger('click');
                                            return false;
                                        }, function(data, ret){
                                            //失败的回调
                                            Layer.alert( ret.msg, {title: "审核"});
                                            return false;
                                        });

                                    },
                                    extend: 'data-area=["350px", "350px"]',
                                    visible: function (row) {
                                       // if(row.status==1||row.status==2){
                                       //     return false;
                                       // }else{
                                           return true;
                                       // }


                                    },

                                }

                            ],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        detail: function () {
            $(document).on('click', '.btn-callback', function () {
                // alert($("input[type='radio']:checked").val())
                var data={};
                data.status=$("input[type='radio']:checked").val();
                data.id=$("input[name=id]").val();
                Fast.api.close(data);
            });


        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});